package com.qire.manhua.model.vo;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.Spannable;
import android.text.SpannableStringBuilder;

import com.qire.common.basic.ObjectUtil;
import com.qire.common.collect.ArrayUtil;
import com.qire.common.support.base.BaseVO;
import com.qire.common.utils.EquipmentInfoUtil;
import com.qire.manhua.model.entity.ComicBookEntity;
import com.qire.manhua.model.entity.ComicBookEntity.ChaptersInfo;
import com.qire.manhua.view.style.RadiusBackgroundSpan;

public class ComicQuickReadInfoVO extends BaseVO {

    public QuickReadDetailsInfoVO bookInfo;         //: {}
    public QuickReadChapterInfoVO chapterInfo;      //: {}
    public QuickReadHistory       readChapter;

    public class QuickReadDetailsInfoVO {
        public int      id;                         //: 10695,
        public String   book_name;                  //: "老婆大人有点冷",
        public String   book_intro;                 //: "因为家族利益她成为了他的妻子，可在婚后他却说：“我给你妻子的头衔，但是我的人跟我的心永远都不会属于你。”几年之后当她一身冰冷如斯的带着一个酷似他的小孩出现在他面前的时候，他的心乱了，而她的情是否也会跟着乱了呢？",
        public TagsVO[] tags;                       //: [],
        public TjVO     tj;                         //: {},
        public int      shelf;                      //: 0,
        public String   end_state;                  //: 0,
        public int      chapter_px;                 //: 84

        public class TjVO {
            public int like_cnt;                    //: 11724;
        }

        public class TagsVO {
            public String tag_name;                 //: "都市",
            public String tag_color;                //: "cfd470
        }

        public CharSequence getTagText() {
            if(ArrayUtil.isEmpty(tags)) {
                return "";
            }

            SpannableStringBuilder builder = new SpannableStringBuilder();
            for(TagsVO tagsVO : tags) {
                int color = Color.parseColor("#" + tagsVO.tag_color);
                RadiusBackgroundSpan bgSpan = new RadiusBackgroundSpan(color, EquipmentInfoUtil.dip2px(2), Paint.Style.FILL_AND_STROKE);//25);

                int startIndex = builder.length();

                String label = tagsVO.tag_name;
                builder.append(label + " ");
                builder.setSpan(bgSpan, startIndex, startIndex + label.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
            }

            return builder;
        }
    }

    public class QuickReadChapterInfoVO {

        public int      id;                              //: 50164,
        public int      next_id;                         //: 50165,
        public String   chapter_name;                    //: "序章",
        public String[] content;                         //: [],
        public SizeVO[] whs;                             //: [],
        public int      content_imgs_count;              //: 16

        public class SizeVO {
            public int w;
            public int h;
        }

        /**
         * 填充漫画章节图片数据
         * @param comicBookEntity 被填充的漫画实体对象
         */
        public void fillComic(ComicBookEntity comicBookEntity) {
            if(ObjectUtil.nonNull(comicBookEntity) && ArrayUtil.notEmpty(content)) {
                ChaptersInfo chaptersInfo = comicBookEntity.chaptersReading(id);

                int pictureRectSize = whs != null ? whs.length : 0;
                Rect[] pictureRectArray = new Rect[pictureRectSize];
                for(int index = 0; index < pictureRectSize; index++) {
                    pictureRectArray[index] = new Rect(0, 0, whs[index].w, whs[index].h);
                }

                chaptersInfo.loadAllPictureResource(content, pictureRectArray);
            }
        }

    }
    public class QuickReadHistory {
        public int id;          //number 必须 章节ID
        public int chapter_px;  //number 必须 章节排序
    }

}
